package id.co.rho.scoring.cid.changecontrol;

import id.co.rho.scoring.cid.changecontrol.entitychange.DeleteEntityChange;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;




public class DeleteCommand implements ChangeControl {

	EntityManager entityManager;
	DeleteEntityChange entityChange;
	Object classEntity;
	Object entityId;
	private Object persistanceEntity;

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public DeleteEntityChange getEntityChange() {
		return entityChange;
	}

	public void setEntityChange(DeleteEntityChange entityChange) {
		this.entityChange = entityChange;
	}
	
	public void setEntityInsert(Object classEntity, Object entityId){
		this.entityId = entityId;
		this.classEntity = classEntity;
	}

	public void execute() {
		try{
		Object persistanceEntity = entityManager.find(
				Class.forName(entityChange.getEntityType()),
				entityChange.getEntityId());
		entityManager.remove(persistanceEntity);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public void executeInsertChange() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void executeUpdateChange() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void executeDeleteChange() {
		// TODO Auto-generated method stub
		
	}

}
